package study_Jsoup;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.junit.Test;

import java.net.URL;

/**
 * 1.根据id查询元素：getElementsById
 * 2.根据标签获取元素：getElementsByTag
 * 3.根据class获取元素：getElementsByClass
 * 4.根据属性获取元素：getElementsAttribute
 * */
public class 使用dom方式遍历文档获取元素 {

    @Test
    public void testDom() throws Exception{
        //解析文件，获取Document
        Document document = Jsoup.parse(new URL("https://www.bilibili.com/"),5000);

        //1.根据id查询元素：getElementsById
        //Element element = document.getElementById("app");

        //2.根据标签获取元素：getElementsByTag
        //Element element1 = document.getElementsByTag("span").first();

        //3.根据class获取元素：getElementsByClass
        //Element element2 = document.getElementsByClass("ie-tips").first();

        //4.根据属性获取元素：getElementsAttribute
        Element element3 = document.getElementsByAttribute("").first();
        //属性+属性值来获取
        Element element4 = document.getElementsByAttributeValue("","").first();


        //打印元素内容
        System.out.println();
    }
}
